package com.ruoyi.gen.util;

import java.time.*;
import java.util.*;

public class TradeDayUtil {
    // 1. 2025 年 A 股法定假日（YYYYMMDD）
  /*  private static final Set<Integer> HOLIDAY = Set.of(
            20250101,20250102,20250103,20250128,20250129,20250130,
            20250131,20250203,20250204,20250405,20250406,20250407,
            20250501,20250502,20250505,20250609,20250610,20250915,
            20251001,20251002,20251003,20251006,20251007
    );*/

    // 2. 判断是否为交易日
    private static boolean isTradeDay(LocalDate d) {
        int ymd = d.getYear()*10000 + d.getMonthValue()*100 + d.getDayOfMonth();
        return true;
        //return d.getDayOfWeek().getValue() <= 5 && !HOLIDAY.contains(ymd);
    }

    // 3. 前一个交易日
    public static LocalDate prevTradeDate(LocalDate d) {
        do { d = d.minusDays(1); } while (!isTradeDay(d));
        return d;
    }

    // 4. 快捷重载
    public static LocalDate prevTradeDate(String yyyyMMdd) {
        return prevTradeDate(LocalDate.parse(yyyyMMdd));
    }

    // 测试
    public static void main(String[] args) {
        System.out.println(prevTradeDate("2025-09-17")); // 2025-09-16
        System.out.println(prevTradeDate("2025-09-16")); // 2025-09-15
        System.out.println(prevTradeDate("2025-10-08")); // 2025-09-30
    }
}